/*
    XTU OJ: 1463
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>

typedef struct {
    int des;
    int source;
    int paste;
    int solve;
    int result;
    int heizi;
    int ikun;
} status;

typedef struct {
    char* str;
    void (* func)(status*);
} command;

void ikun(status* stat) {
    stat -> ikun = 1;
}

void heizi(status* stat) {
    stat -> heizi = 1;
}

void desc(status* stat) {
    stat -> des = 1;
}

void source(status* stat) {
    stat -> source = 1;
}

void paste(status* stat) {
    stat -> paste = 1;
}

void solve(status* stat) {
    stat -> solve = 1;
}

void result(status* stat) {
    stat -> result = 1;
}

command funcs[] = {
    {"i_am_ikun", ikun},
    {"i_am_xiaoheizi", heizi},
    {"problem_describe", desc},
    {"problem_source", source},
    {"problem_num", source},
    {"code_paste", paste},
    {"solve", solve},
    {"result", result}
};

int func_length = sizeof(funcs) / sizeof(command);

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        int n;
        scanf("%*s%d ", &n);
        status status = {0, 0, 0, 0, 0, 0, 0};
        for (int j = 0; j < n; j++) {
            int c, pos = 0;
            char command[100];
            while (c = getchar(), c != '\n') {
                if (c >= 'a' && c <= 'z') {
                    command[pos++] = c;
                } else if (c >= 'A' && c <= 'Z') {
                    command[pos++] = c - 'A' + 'a';
                } else if (c == '_') {
                    command[pos++] = c;
                }
            }
            command[pos] = '\0';
            if (pos != 0) {
                for (int k = 0; k < func_length; k++) {
                    if (strcmp(funcs[k].str, command) == 0) {
                        funcs[k].func(&status);
                        break;
                    }
                }
            }
        }
        if (status.heizi) {
            puts("5");
        } else if (status.ikun) {
            int answer = status.des && status.paste;
            puts(answer ? "4" : "3");
        } else {
            int answer = status.des && status.source && status.paste && status.solve && status.result;
            puts(answer ? "1" : "2");
        }
    }
    return 0;
}
